//
//  ZZQHotViewController.m
//  zzqKanBoKe
//
//  Created by ben on 17/2/6.
//  Copyright © 2017年 张增强. All rights reserved.
//

#import "ZZQHotViewController.h"
#import "ZZQLiveHandler.h"
#import "ZZQLiveCell.h"
#import "ZZQPlayerViewController.h"

static NSString * identifier = @"ZZQLiveCell";

@interface ZZQHotViewController ()
@property(nonatomic, strong)NSMutableArray * datalist;
@end

@implementation ZZQHotViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
//    self.view.backgroundColor = [UIColor blueColor];
    self.tableView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-64-49);
    
    
    [self loadData];
    [self initUI];
    
}

- (NSMutableArray *)datalist{
    if(!_datalist){
        _datalist = [NSMutableArray array];
    }
    return _datalist;
}


- (void)initUI{
    NSLog(@"initUI");
    [self.tableView registerNib:[UINib nibWithNibName:@"ZZQLiveCell" bundle:nil] forCellReuseIdentifier:identifier];
    //设置tableview的显示效果
    self.tableView.showsVerticalScrollIndicator = NO;
    self.tableView.showsHorizontalScrollIndicator = NO;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
//    self.automaticallyAdjustsScrollViewInsets = YES;
}

- (void)loadData{
    NSLog(@"sss");
     [ZZQLiveHandler executeGetHotLiveTaskWithSuccess:^(id obj) {
         [self.datalist addObjectsFromArray:obj];
         [self.tableView reloadData];
     } failed:^(id obj) {
         NSLog(@"error:%@", obj);
     }];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.datalist.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    ZZQLiveCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    cell.live = self.datalist[indexPath.row];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 70 + SCREEN_WIDTH + 20;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
    ZZQLive * live = self.datalist[indexPath.row];
    ZZQPlayerViewController * playVC = [[ZZQPlayerViewController alloc] init];
    playVC.live = live;
    [self.navigationController pushViewController:playVC animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
